#include <iostream>
#include <memory>
#include <functional>

class TcpConnection {
public:
    TcpConnection(int id) : connectionId(id) {}
    int getConnectionId() const { return connectionId; }
    void close() { std::cout << "Connection " << connectionId << " closed." << std::endl; }
private:
    int connectionId;
};

void handleCloseCallback(std::shared_ptr<TcpConnection> conn) {
    std::cout << "Handling close for connection " << conn->getConnectionId() << std::endl;
    conn->close();
}

int main() {
    using CloseCallBack = std::function<void(std::shared_ptr<TcpConnection> conn)>;
    std::shared_ptr<TcpConnection> connection1 = std::make_shared<TcpConnection>(1);
    CloseCallBack callback1 = handleCloseCallback;
    callback1(connection1);

    std::shared_ptr<TcpConnection> connection2 = std::make_shared<TcpConnection>(2);
    CloseCallBack callback2 = [](std::shared_ptr<TcpConnection> conn) {
        std::cout << "Alternative handling for connection " << conn->getConnectionId() << std::endl;
        conn->close();
    };
    callback2(connection2);

    return 0;
}